package {	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	public class Switch extends MovieClip {
				
		private var _state:uint; //0 = center, 1 left, 2 right
		private var s1Clicked:Boolean;
		private var s2Clicked:Boolean;
		
		public function Switch() {			
			//addEventListener(MouseEvent.MOUSE_OUT, mouseReleased);
			//addEventListener(MouseEvent.MOUSE_UP, mouseReleased);			
			addEventListener(Event.ENTER_FRAME, enterFrame);			
		}											
		
		public function mouseReleased(e:MouseEvent):void 
		{
			s1Clicked = false;
			s2Clicked = false;
		}
		
		public function getState():uint 
		{
			return state;
		}
		
		private function enterFrame(e:Event):void 
		{						
			if (s1Clicked) {
				state = 1;
			}
			else if (s2Clicked) {
				state = 2;
			}
			else {
				state = 0;				
			}
			gotoAndStop(state+1);									
		}
		
		public function mouseClickedS1(e:MouseEvent):void 
		{
			s1Clicked = true;
		}		
			
		public function mouseClickedS2(e:MouseEvent):void 
		{
			s2Clicked = true;
		}
		
		public function get state():uint 
		{
			return _state;
		}
		
		public function set state(value:uint):void 
		{
			_state = value;		
			gotoAndStop(state+1);		
		}
	}
}
